package com.leil.movies.common;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonAlias;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

@RestControllerAdvice
public class CommonExceptionHandler {

    /**
     * 通用异常处理
     * @param request
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public JSONObject exceptionHandle(HttpServletRequest request, Exception e) {
        JSONObject json = new JSONObject();
        json.put("code", 400);
        json.put("err", e.getMessage());
        return json;
    }


}
